/*
 * @Description:
 * @Author: ldx
 * @Date: 2022-09-28 21:41:54
 * @LastEditors: ldx
 * @LastEditTime: 2022-09-29 22:27:11
 */
// import { useState } from 'react'
import JSEncrypt from 'jsencrypt'
import { useRecoilValue } from 'recoil'

import { commonState } from '@/recoil'
const useRsa = (): ((value: string) => void) => {
  // const [permissions, setPermissions] = useState('')
  const publicKey = useRecoilValue(commonState.publicKey)
  // const publicKey =
  //   'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCRkrl/w2r2ZfBo8a8dzhRjt6Xk+E2dwjYVS2UHq/2ekRWWD/lufqBXVM1XpOm9X9uQ2L2H1hhClZx2DDOVT0u3BJ9ZRpEM0olFtoX54VfCnr9JP8MyWK7yiFXOmiSfVD+bFYPaYKEdEkzyd5CT3LI3mhd9wjzBcZlLPQmHojQSxQIDAQAB'
  const encrypt = new JSEncrypt()
  encrypt.setPublicKey(publicKey)

  const rasEncrypt = (value: string): string | false => {
    const encrypted = encrypt.encrypt(value) as string
    // const decrypt = new JSEncrypt()
    // decrypt.setPrivateKey(publicKey)

    return encrypted
    // return value
  }
  return rasEncrypt
}
export default useRsa
